package com.liuym.admin.task;

import com.liuym.admin.repository.mapper.ExportLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.xml.crypto.Data;
import java.util.Calendar;
import java.util.Date;

/**
 * @author Liuym
 * @date 2019/04/05 15:05
 * @describe：定时清理exoprtLog表
 */
@Component
public class ExportTask {


    @Autowired
    private ExportLogMapper exportLogMapper;

    /**
     * 定时任务，每天0点执行
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    public void deleteExportByTime() {
        Calendar c = Calendar.getInstance();
        //过去七天
        c.setTime(new Date());
        c.add(Calendar.DATE, - 7);
        Date d = c.getTime();
        exportLogMapper.deleteByTime(d);
    }

}
